package io.gimo.study.design_pattern.factory.abstract_factory;


import io.gimo.study.design_pattern.factory.abstract_factory.factory.*;

/**
 * 抽象工厂测试类
 *
 * @author GimoXie
 */
public class AbstractFactoryTest {

    public static void main(String[] args) {

        // 抽象工厂
        Provider pro;
        // 工厂要加工的产品
        Sortor sortor;
        Searcher searcher;

        int[] target = {2, 4, 3, 1, 5, 7, 6};

        // 选择排序
        System.out.println("选择排序...");
        pro = new SelectSortorFactory();
        sortor = (Sortor) pro.produce();
        sortor.sort(target);

        // 冒泡排序
        System.out.println("冒泡排序...");
        pro = new BubbleSortorFactory();
        sortor = (Sortor) pro.produce();
        sortor.sort(target);

        // 快速排序
        System.out.println("快速排序...");
        pro = new QuickSortorFactory();
        sortor = (Sortor) pro.produce();
        sortor.sort(target);

        // 二分插入排序
        System.out.println("二分插入排序...");
        pro = new BinaryInsertionSortorFactory();
        sortor = (Sortor) pro.produce();
        sortor.sort(target);

        // 直接插入排序
        System.out.println("直接插入排序...");
        pro = new InsertionSortorFactory();
        sortor = (Sortor) pro.produce();
        sortor.sort(target);

        // 基数排序
        System.out.println("基数排序...");
        pro = (Provider) new RadixSortorFactory();
        sortor = (Sortor) pro.produce();
        sortor.sort(target);

        // 希尔排序
        System.out.println("希尔排序");
        pro = new ShellSortorFactory();
        sortor = (Sortor) pro.produce();
        sortor.sort(target);

        // 归并排序排序
        System.out.println("归并排序...");
        pro = new MergeSortorFactory();
        sortor = (Sortor) pro.produce();
        sortor.sort(target);

        // 堆排序
        System.out.println("堆排序...");
        pro = new HeapSortorFactory();
        sortor = (Sortor) pro.produce();
        sortor.sort(target);


        // 顺序查找
        System.out.println("顺序查找...");
        pro = new OrderSearcherFactory();
        searcher = (Searcher) pro.produce();
        System.out.println(searcher.search(target, 2));

        // 二分查找
        System.out.println("二分查找...");
        pro = new BinarySearcherFactory();
        searcher = (Searcher) pro.produce();
        System.out.println(searcher.search(target, 2));

        // 哈希查找
        System.out.println("哈希查找...");
        pro = new HashSearcherFactory();
        searcher = (Searcher) pro.produce();
        System.out.println(searcher.search(target, 4));
    }
}
